<%@page import="javax.portlet.PortletSession"%>
<%@ include file="/html/init.jsp" %>

<liferay-ui:journal-article articleId="13002"
	groupId="<%=themeDisplay.getScopeGroupId()%>"
	languageId="<%=themeDisplay.getLanguageId()%>" />

Max Capacity of this library: <%= portletConfig.getInitParameter("max-books") %>

<portlet:renderURL var="addBookURL">
	<portlet:param name="jspPage" value="/html/form.jsp"/>
</portlet:renderURL>

<br/><a href="<%= addBookURL %>"><liferay-ui:message key="add-book"/></a>

<br/><a href="javascript:void();" onclick="javascript:openPopup();">Add Book Popup</a>

<portlet:renderURL var="listBooksURL">
	<portlet:param name="jspPage" value="/html/list.jsp"/>
</portlet:renderURL>

<br/><a href="<%= listBooksURL %>">List Books</a>

<%@ include file="/html/search.jspf" %>

<aui:script>
	function openPopup() {		
		var ajaxURL = Liferay.PortletURL.createRenderURL();
		ajaxURL.setPortletId('<%= themeDisplay.getPortletDisplay().getRootPortletId() %>');
		ajaxURL.setParameter('jspPage', '/html/form.jsp');
		ajaxURL.setWindowState('pop_up'); 
		
		AUI().use('liferay-util-window', function(A) {
			Liferay.Util.openWindow({
            		dialog: {
                		centered: true,
                    	modal: true,
                    	width: 600,
                    	height: 400,
                    	destroyOnHide: true           
               	},
                	title: 'Add/Update Book',
               	uri: ajaxURL
           	});     
        	});		
	}
	
	AUI().ready(function(A) {
		Liferay.on('addBookEvent', function(payload) {
			alert('I am here on you second portlet...' + payload.bookTitle);
		});
	});
</aui:script>

<h4><%= ParamUtil.getString(renderRequest, "GREETING") %></h4>

<h3><%= portletSession.getAttribute("SUCCESS_MSG", PortletSession.APPLICATION_SCOPE) %></h3>